#ifdef RT_USE_OLD_CONN_WRAP

#if !defined CS_SEND_BUF_H  && !defined (_NEW_PROTO_TP)
#define CS_SEND_BUF_H

#include <list>
#include "RtCnPdu.h"

using namespace std;

// #define PRINT_CONN_DETAIL_LOG

#define FULL_RELIABLE	1			//Full reliable mode
#define SEQUENCE_LIMIT	0xFFF00000	//For Seq# rewind

class /*RT_API_EXPORT*/ CRtCnSendBuf  
{
public:
	CRtCnSendBuf(DWORD dwMaxBufLen);
	virtual ~CRtCnSendBuf();

	void Reset();
	void SetMaxBufLen(DWORD dwMaxBufLen);
	DWORD GetMaxBufLen();
public:
	//return : data length real accepted
	DWORD AddDataPDU(CRtMessageBlock *pData, BOOL bPDUNeedACK);
	DWORD AddKeepAlivePDU();
	DWORD AddDisconnPDU(RtResult aReason);

	BYTE GetData(CRtMessageBlock* &pmb, DWORD& dwMsgACK);//get data ready for sending
	void DataSentLen(DWORD dwDataLen);//How many data have been sent this time
	int DoACK(DWORD dwSeqACKed);//ACK comes
	int DoReconnACK(DWORD dwSeqACKed);//when reconnecting ACK comes
	void SetSeq4ACK(DWORD dwSeq4ACK);

	void ClearAllSent();
private:
//	int AddToList(CRtCnPduSendItem *pSendPDU, DWORD dwLen);
	void AddToList(CRtCnPduSendItem *pSendPDU);
	DWORD DropDataIfCan(DWORD dwBytes);
	void PrepareSendMB();
private:
	DWORD m_dwMaxBufLen;				//Max of buf length
	list<CRtCnPduSendItem*> m_listPDU;	//list of PDU packages need to be send
	CRtCnPduSendItem *m_pSendPDU;			//Current sending PDU
	CRtMessageBlock *m_pmb;				//mb of current sending PDU
	DWORD m_dwPDUStartSeq;				//start sequence of every PDU
	DWORD m_dwSeqACKed;					//sequence ACKed by peer
	DWORD m_dwSeq4ACK;					//sequence for ACK to peer
	DWORD m_dwOldSeq4ACK;

	//Bytes Counter of All kinds of PDUs
	DWORD m_dwRoomsUsed;

#ifdef PRINT_CONN_DETAIL_LOG
	int m_sendNum;
#endif
};

#endif // #ifndef CS_SEND_BUF_H

#endif // RT_USE_OLD_CONN_WRAP

